<?php

// 抽奖活动表

namespace app\console\model;

use think\Model;
use think\Request;

class LuckDraw extends Model
{

    // 抽奖状态 获取器
    protected function getStatusTextAttr($value, $data)
    {
        $status = ['1' => '已开奖', '2' => '未开奖'];

        return $status[$data['status']];
    }


    // 模型事件
    protected static function init()
    {
        // 写入之前
        self::event('before_write', function ($data) {

            // 创建时间
            $data->create_time = date('Y-m-d', time());

            $data->picUrl = uploadImg('picUrl');
            $data->pc_url = uploadImg('pc_url');
            $data->thumb_img = show_thumb_pic($data->picUrl);

            // 开奖时间
            $data->start_time = strtotime(Request::instance()->param('start_time'));
        });
    }
}